package datastructure.tree;

/**
 *
 * @author Lei
 */
public class IsSubTree {

    // check if tree s is a sub tree of t
    public boolean isSubTree(TreeNode t, TreeNode s) {
        if (s == null) {
            return true;
        }

        if (t == null) {
            return false;
        }

        if (IsBinaryTreeIdentical.isBinaryTreeIdentical(t, s)) {
            return true;
        }
        else {
            return IsBinaryTreeIdentical.isBinaryTreeIdentical(t.left, s)
                    || IsBinaryTreeIdentical.isBinaryTreeIdentical(t.right, s);
        }
    }
}
